package net.m2m.apbnm.healthcaresensordevice.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;



import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;




import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.view.client.TreeViewModel;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.TreeViewModel.NodeInfo;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel;
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.TreeViewModel.DefaultNodeInfo;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Grid;


public class HealthcareSensorDeviceConfiguration implements EntryPoint {
	
	private static class Playlist {
	    private final String name;
	    private final List<String> songs = new ArrayList<String>();

	    public Playlist(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a song to the playlist.
	     * 
	     * @param name the name of the song
	     */
	    public void addSong(String name) {
	      songs.add(name);
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the list of songs in the playlist.
	     */
	    public List<String> getSongs() {
	      return songs;
	    }
	  }

	  /**
	   * A composer of classical music.
	   */
	  private static class Composer {
	    private final String name;
	    private final List<Playlist> playlists = new ArrayList<Playlist>();

	    public Composer(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a playlist to the composer.
	     * 
	     * @param playlist the playlist to add
	     */
	    public Playlist addPlaylist(Playlist playlist) {
	      playlists.add(playlist);
	      return playlist;
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the rockin' playlist for this composer.
	     */
	    public List<Playlist> getPlaylists() {
	      return playlists;
	    }
	  }
	
	///////////////////////////////////////
	//Cell Tree
	  private static class CustomTreeModel implements TreeViewModel {

		    private final List<Composer> composers;

		    /**
		     * This selection model is shared across all leaf nodes. A selection model
		     * can also be shared across all nodes in the tree, or each set of child
		     * nodes can have its own instance. This gives you flexibility to determine
		     * how nodes are selected.
		     */
		    private final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();

		    public CustomTreeModel() {
		      // Create a database of information.
		      composers = new ArrayList<Composer>();

		      // Add compositions by Beethoven.
		      {
		        Composer beethoven = new Composer("Patient Info");
		        composers.add(beethoven);

		        Playlist concertos = beethoven.addPlaylist(new Playlist("add/edit basic medical info"));
		        Playlist quartets = beethoven.addPlaylist(new Playlist("add/edit healthcare sensor configuration"));
		        
		      }
		      
		      
		      {
			        Composer beethoven = new Composer("Patient Health Record");
			        composers.add(beethoven);

			        Playlist concertos = beethoven.addPlaylist(new Playlist("Emergency View"));
			        Playlist quartets = beethoven.addPlaylist(new Playlist("General View"));
			        
			        
			        
			      }

		      

		      
		      {
			        Composer healthcaresensor = new Composer("Healthcare Sensor Device Settings");
			        composers.add(healthcaresensor);
			        Playlist concertos = healthcaresensor.addPlaylist(new Playlist("ekg sensor"));
			        Playlist concertos1 = healthcaresensor.addPlaylist(new Playlist("blood pressure sensor"));
			        Playlist concertos2 = healthcaresensor.addPlaylist(new Playlist("pulse oximetry sensor"));
			        
			        
			        
			        
			      }

		      // Add compositions by Brahms.
		      
		    }

		    /**
		     * Get the {@link NodeInfo} that provides the children of the specified
		     * value.
		     */
		    public <T> NodeInfo<?> getNodeInfo(T value) {
		      if (value == null) {
		        // LEVEL 0.
		        // We passed null as the root value. Return the composers.

		        // Create a data provider that contains the list of composers.
		        ListDataProvider<Composer> dataProvider = new ListDataProvider<HealthcareSensorDeviceConfiguration.Composer>(
		            composers);

		        // Create a cell to display a composer.
		        Cell<Composer> cell = new AbstractCell<Composer>() {
		          @Override
		          public void render(Context context, Composer value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };

		        // Return a node info that pairs the data provider and the cell.
		        return new DefaultNodeInfo<Composer>(dataProvider, cell);
		      } else if (value instanceof Composer) {
		        // LEVEL 1.
		        // We want the children of the composer. Return the playlists.
		        ListDataProvider<Playlist> dataProvider = new ListDataProvider<Playlist>(
		            ((Composer) value).getPlaylists());
		        Cell<Playlist> cell = new AbstractCell<Playlist>() {
		          @Override
		          public void render(Context context, Playlist value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };
		        return new DefaultNodeInfo<Playlist>(dataProvider, cell);
		      } else if (value instanceof Playlist) {
		        // LEVEL 2 - LEAF.
		        // We want the children of the playlist. Return the songs.
		        ListDataProvider<String> dataProvider = new ListDataProvider<String>(
		            ((Playlist) value).getSongs());

		        // Use the shared selection model.
		        return new DefaultNodeInfo<String>(dataProvider, new TextCell(),
		            selectionModel, null);
		      }

		      return null;
		    }

		    /**
		     * Check if the specified value represents a leaf node. Leaf nodes cannot be
		     * opened.
		     */
		    public boolean isLeaf(Object value) {
		      // The leaf nodes are the songs, which are Strings.
		      if (value instanceof String) {
		        return true;
		      }
		      return false;
		    }

		  }
	

	
	
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		rootPanel.add(absolutePanel, 10, 10);
		absolutePanel.setSize("217px", "711px");
		
		

		TreeViewModel model = new CustomTreeModel();
		CellTree cellTree = new CellTree(model,null);
		cellTree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

		    // Open the first playlist by default.
		TreeNode rootNode = cellTree.getRootTreeNode();
		TreeNode firstPlaylist = rootNode.setChildOpen(0, true);
		firstPlaylist.setChildOpen(0, true);

		
		absolutePanel.add(cellTree, 37, 47);
		cellTree.setSize("150px", "654px");
		
		AbsolutePanel absolutePanel_1 = new AbsolutePanel();
		rootPanel.add(absolutePanel_1, 233, 10);
		absolutePanel_1.setSize("507px", "651px");
		
		Label lblParameter = new Label("Parameter");
		absolutePanel_1.add(lblParameter, 32, 99);
		
		Label lblDatatype = new Label("Datatype");
		absolutePanel_1.add(lblDatatype, 284, 99);
		
		TextBox textBox_1 = new TextBox();
		absolutePanel_1.add(textBox_1, 219, 154);
		textBox_1.setSize("36px", "15px");
		
		TextBox textBox_2 = new TextBox();
		absolutePanel_1.add(textBox_2, 284, 125);
		textBox_2.setSize("95px", "15px");
		
		TextBox textBox_3 = new TextBox();
		absolutePanel_1.add(textBox_3, 284, 154);
		textBox_3.setSize("95px", "15px");
		
		TextBox textBox_4 = new TextBox();
		absolutePanel_1.add(textBox_4, 32, 121);
		
		TextBox textBox_5 = new TextBox();
		absolutePanel_1.add(textBox_5, 32, 154);
		textBox_5.setSize("152px", "15px");
		
		Label lblSensorprofile = new Label("sensor-profile");
		absolutePanel_1.add(lblSensorprofile, 32, 77);
		
		Label lblSensingInterval = new Label("sensing interval");
		absolutePanel_1.add(lblSensingInterval, 32, 239);
		
		Button btnAccept = new Button("Accept");
		absolutePanel_1.add(btnAccept, 32, 589);
		
		Button btnSave = new Button("Save");
		absolutePanel_1.add(btnSave, 105, 589);
		
		CheckBox chckbxsgeneral = new CheckBox("30s (Normal)");
		absolutePanel_1.add(chckbxsgeneral, 32, 261);
		
		CheckBox chckbxsprone = new CheckBox("15s(Prone)");
		absolutePanel_1.add(chckbxsprone, 32, 283);
		
		Label lblCommunicationInterval = new Label("communication interval");
		absolutePanel_1.add(lblCommunicationInterval, 32, 376);
		
		CheckBox chckbxs = new CheckBox("60s(Normal)");
		absolutePanel_1.add(chckbxs, 32, 398);
		
		CheckBox chckbxsprone_1 = new CheckBox("30s(Prone)");
		absolutePanel_1.add(chckbxsprone_1, 32, 423);
		
		CheckBox chckbxscritical_1 = new CheckBox("10s(Critical)");
		absolutePanel_1.add(chckbxscritical_1, 32, 442);
		
		Label lblUnit = new Label("Unit");
		absolutePanel_1.add(lblUnit, 221, 99);
		
		TextBox textBox = new TextBox();
		absolutePanel_1.add(textBox, 219, 125);
		textBox.setSize("36px", "15px");
		
		Label lblEkgSensorconfiguration = new Label("Blood Presssure Sensor-Configuration");
		absolutePanel_1.add(lblEkgSensorconfiguration, 32, 47);
		
		
		
		
		
      
      
      ///////////////////////////////////////////////////////////////////////////
	
	}
}



